package com.nas.app;

import java.util.PriorityQueue;

public class MessageQueue {

    private PriorityQueue<String> messages;
    
    private boolean empty = true;
    
    public synchronized String take() {
        //Wait until message is available.
        while (empty) {
            try {
                wait();
            } catch (InterruptedException e) {}
        }
        //Toggle status.
        empty = true;
        //Notify producer that status has changed.
        notifyAll();
        return messages.poll();
    }
    
}
